<?php
/**
 * @Notes:【】
 * @Date: 2022-06-02 23:31
 */

namespace App\Service\Task;

use App\Dao\Task\TaskReportDao;
use App\Dao\Task\TaskReportTypeDao;
use App\Service\BaseService;
use Hyperf\Di\Annotation\Inject;

class TaskReportService extends BaseService
{

    /**
     * @Inject()
     * @var TaskReportDao
     */
    protected $taskReportDao;
    /**
     * @Inject()
     * @var TaskReportTypeDao
     */
    protected $taskReportTypeDao;

    public function getTypes()
    {
        return $this->taskReportTypeDao->page(false)->lists(_Collect([]));
    }

    public function add(\App\Tool\Collect $data)
    {
        return $this->taskReportDao->add($data);
    }

    public function lists($params){
        $data = $this->taskReportDao->lists($params);
        return $data;
    }

    public function listsByType(int $userId, int $type)
    {
        $data = $this->taskReportDao->where(function($query) use($type,$userId){
                if($type==0){
                    $query->where('user_id',$userId);
                }else{
                    $query->where('task_user_id',$userId);
                }
        })->getList();
        _SUCCESS($data);
    }


    public function setStatus($id, $data)
    {
        $this->taskReportDao->setStatus($id, $data->get('status'),$data->get('reason'));
        return true;
    }


}